package parts_of_sentence;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;

public class Sentence {
	public static final Logger LOG = Logger.getLogger(Sentence.class);
	private String sentence;
	private List<Word> listWords = new ArrayList<Word>();

	public Sentence(String sentence) {
		this.sentence = sentence;
		fillListWords();
	}

	private void fillListWords() {
		String R = "([A-Za-z\'\"].+?[ .?!])";
		Pattern p = Pattern.compile(R);
		Matcher m = p.matcher(sentence);
		while (m.find()) {
			listWords.add(new Word(m.group()));
			LOG.info("added word");
		}
	}

	public void deleteWordByLength(int length) {		
		for(Iterator<Word>it = listWords.iterator(); it.hasNext();){
			String next = it.next().getWord();
			if(next.length()==length){
				it.remove();
				LOG.info("word is removing");
			}
		}
	}
	
	public String collectSentence() {
		String collectedSentence = "";
		for (Word w : listWords) {
			collectedSentence = collectedSentence + " " 
								+ w.collectWord();
		}
		return collectedSentence;

	}
	
	public List<Word> getListWords() {
		return listWords;
	}

	public String getSentence() {
		return sentence;
	}

	
}
